package com.itboye.mengwu.app.ui.main;

import java.util.Observable;
import java.util.Observer;

import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.mengwu.R;
import com.itboye.mengwu.data.model.ReportModel;
import com.itboye.mengwu.data.presenter.ReportPresenter;
import com.itboye.mengwu.data.presenter.TieZiPresenter;

public class ActivityReport extends BaseActivity implements Observer {
	String reportTid;
	String reportID;
	String reportedID;
	String reportReson;
	String reporType;
	ReportPresenter reportPresenter;
	ReportModel reportModel;
	EditText ed;
	TextView ok;
	ImageView back;
	TextView txt_title;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_report;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		txt_title.setText("举报理由");
		reportPresenter = new ReportPresenter(this);
		reportModel = new ReportModel();
		reporType = getIntent().getStringExtra("Report_type");
		reportID = getIntent().getStringExtra("Op_uid");
		reportedID = getIntent().getStringExtra("toUid");
		reportTid = getIntent().getStringExtra("Report_id");
		ok.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				reportModel.setReport_type(reporType);
				reportModel.setOp_uid(reportID);
				reportModel.setUid(reportedID);
				reportModel.setReport_id(reportTid);
				if (ed.getText() == null || ed.getText().toString() == "") {
					ByAlert.alert("举报理由不能为空");
					return;
				} else {
					reportModel.setReason(ed.getText() + "");
				}
				reportPresenter.add(reportModel);
				// finish();
			}
		});
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ed.setText("");
				finish();
			}
		});

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity info = handlerError(data);
		if (info != null) {
			// ByAlert.alert("" + info.getData());
			if (info.getEventType() == ReportPresenter.ReportSuccess) {
				Log.e("hu", "success");
				ByAlert.alert("举报成功，我们会尽快处理");
				finish();
			}
		}

	}

}
